<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        // 递归  就是 自己调用自己
        // function demo() {
        //     // console.log("")
        //     demo();
        // }
        // var obj = {
        //     name: '123'
        // }
        // var obj1 = obj

        // obj1.name = "发发发";
        // console.log(obj.name)  // 123

        // var a = 123;
        // var b = a;
        // b = 456
        // console.log(a) // 123

        // 如何进行深度拷贝呢
        var obj = {
            name: "666",
            list: [1, 2, 3, 4],
            data: {
                msg: '888'
            }
        }

        // 1. 最简单的
        // var obj1 = JSON.parse(JSON.stringify(obj))

        // 2. 用递归
        function deepClone(target) {
            if(typeof target === "string" || typeof target === "number" || typeof target === "boolean" || typeof target === "undefined") {
                return target;
            }else if(Array.isArray(target)) {
                var arr = [];
                target.forEach((item)=> {
                    arr.push(item)
                })

                return arr;
            }else if(typeof target === "object") {
                var obj = {};
                for(let key in target) {
                    // obj['name'] = "666"
                    // obj['list'] = [1,2,3,4]
                    // obj['data'] = {msg:"888"}
                    obj[key] = deepClone(target[key])
                }

                return obj
            }
        }

        var obj1 = deepClone(obj)
        console.log(obj1 === obj)
        
    </script>
</body>
</html>